Support AutoGeneratedTimestamp annotations in nested objects#6546
Conversation
e5a53cb to
f9dc918
Compare
f09f819 to
bad2a18
Compare
7a8a1da to
778d12b
Compare
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Outdated
Show resolved
Hide resolved
shetsa-amzn
left a comment
There was a problem hiding this comment.
What happens If user annotates (DynamoDbAutoGeneratedTimestampAttribute) a non-Instant field
...ftware/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java
Show resolved
Hide resolved
shetsa-amzn
left a comment
There was a problem hiding this comment.
Overall, is there is any chance this fix will cause backward compatible issues for customers who relied on wrong behavior before?
...ava/software/amazon/awssdk/enhanced/dynamodb/functionaltests/AutogeneratedTimestampTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/enhanced/dynamodb/functionaltests/AutogeneratedTimestampTest.java
Outdated
Show resolved
Hide resolved
...are/amazon/awssdk/enhanced/dynamodb/functionaltests/models/AutogeneratedTimestampModels.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/enhanced/dynamodb/functionaltests/AutogeneratedTimestampTest.java
Outdated
Show resolved
Hide resolved
Hello @shetsa-amzn, There should be no backward compatibility issues unless customers have used @DynamoDbAutoGeneratedTimestampAttribute or @DynamoDbUpdateBehavior annotations on nested fields. If they previously relied on tests or validation to prevent these annotations on nested fields, those tests may now fail at compile time and the issues can be addressed with minor code changes. In summary, customers who did not use these annotations on nested fields will not be affected, and any issues for those who did can be resolved with minor code changes. |
Hello @shetsa-amzn, For cases where a user annotates a non-Instant field with @DynamoDbAutoGeneratedTimestampAttribute, there is a validation in place within the AutoGeneratedTimestampRecordExtension class, in validateType() method: public <R> void validateType(
String attributeName,
EnhancedType<R> type,
AttributeValueType attributeValueType) {
// ...
if (!type.rawClass().equals(Instant.class)) {
throw new IllegalArgumentException(String.format(
"Attribute '%s' of Class type %s is not a suitable Java Class type to be used as a Auto Generated "
+ "Timestamp attribute. Only java.time.Instant Class type is supported.",
attributeName,
type.rawClass()));
}
}This behavior is also covered by autogenerateTimestamps_onNonInstantAttribute_throwsException() test in AutoGeneratedTimestampExtensionTest.java. |
…-updateBehavior-annotations-in-nested-objects
…-updateBehavior-annotations-in-nested-objects
…-updateBehavior-annotations-in-nested-objects
- Remove NestedUpdateBehaviorTest.java - tests for nested update behavior support - Remove UpdateBehaviorTestModels.java - test models for nested update behavior These files will be included in a separate PR for nested update behavior support.
…tes within nested objects
…tes within nested objects
...are/amazon/awssdk/enhanced/dynamodb/functionaltests/AutoGeneratedTimestampExtensionTest.java
Show resolved
Hide resolved
…-updateBehavior-annotations-in-nested-objects
…tes within nested objects
…tes within nested objects
…tes within nested objects
…tes within nested objects
…tes within nested objects
…-updateBehavior-annotations-in-nested-objects
…-updateBehavior-annotations-in-nested-objects
…-updateBehavior-annotations-in-nested-objects
…estamp-and-updateBehavior-annotations-in-nested-objects' into feature/support-autoGeneratedTimestamp-and-updateBehavior-annotations-in-nested-objects
…-updateBehavior-annotations-in-nested-objects
Description
This pull request adds support for applying
@DynamoDbAutoGeneratedTimestampAttributeto attributes within nested objects. Auto-generated timestamps are now applied consistently across both top-level and nested attributes, including deeply nested and recursive object graphs.The implementation also introduces a caching mechanism for nested schema resolution to improve performance and safely support recursive or circular references.
Motivation and Context
Previously,
@DynamoDbAutoGeneratedTimestampAttributewas evaluated only for top-level attributes. As a result, timestamp auto-generation did not work for nested attributes, limiting its usefulness when modeling complex domain objects.In addition, nested schema resolution relied on repeatedly invoking
getNestedSchema()for each nested object instance. In deeply nested or recursive structures, this could lead to redundant processing and unnecessary performance overhead.This change addresses both limitations by:
Modifications
Nested Timestamp Support
AutoGeneratedTimestampRecordExtensionhas been enhanced to detect and apply the timestamp annotation on nested attributes.Depending on the operation type and the configured
IgnoreNullsMode, nested objects may be represented during update operations in one of two ways:_NESTED_ATTR_UPDATE_marker, as produced byUpdateItemOperation.transformItemToMapForUpdateExpression.Both representations are now supported, and a single generated timestamp value is applied consistently across top-level and nested attributes.
Testing
Existing tests were updated where necessary, and new tests were added to validate the new behavior.
Test Coverage on modified classes:
Test Coverage Checklist
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License